# Maintainer:  Jonathan Steel <jsteel at archlinux.org>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Duck Hunt <vaporeon@tfwno.gf>

pkgbase=mgba
pkgname=('libmgba' 'mgba-sdl' 'mgba-qt')
pkgver=0.10.2
pkgrel=2
arch=('loong64' 'x86_64')
url='http://mgba.io'
license=('custom:MPL2')
makedepends=('cmake' 'qt5-multimedia' 'sdl2' 'zlib' 'libpng' 'libzip' 'libedit'
             'ffmpeg' 'desktop-file-utils' 'qt5-tools' 'lua')
optdepends=('lua: scripting support')
source=($pkgbase-$pkgver.tar.gz::https://github.com/mgba-emu/mgba/archive/$pkgver.tar.gz)
sha256sums=('60afef8fb79ba1f7be565b737bae73c6604a790391c737f291482a7422d675ae')

build() {
  cmake -B build -S mgba-$pkgver \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -Wno-dev
  cmake --build build
}

package_libmgba() {
  pkgdesc='Shared library of mGBA'
  depends=('zlib' 'libpng' 'libzip' 'libedit' 'ffmpeg' 'sqlite')

  cmake -DCOMPONENT=libmgba mgba-$pkgver -DCMAKE_INSTALL_PREFIX="$pkgdir/usr" \
    -P build/cmake_install.cmake

  cmake -DCOMPONENT=mgba-dev mgba-$pkgver -DCMAKE_INSTALL_PREFIX="$pkgdir/usr" \
    -P build/cmake_install.cmake

  install -Dm644 mgba-$pkgver/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_mgba-sdl() {
  pkgdesc='A Nintendo Gameboy Advance Emulator focusing on both speed and accuracy'
  depends=('libmgba' 'sdl2')

  cmake -DCOMPONENT=mgba-sdl mgba-$pkgver -DCMAKE_INSTALL_PREFIX="$pkgdir/usr" \
    -P build/cmake_install.cmake

  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s /usr/share/licenses/libmgba/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_mgba-qt() {
  pkgdesc='A Nintendo Gameboy Advance Emulator focusing on both speed and accuracy. Qt5 UI.'
  depends=('libmgba' 'qt5-multimedia' 'sdl2')

  cmake -DCOMPONENT=mgba-qt mgba-$pkgver -DCMAKE_INSTALL_PREFIX="$pkgdir/usr" \
    -P build/cmake_install.cmake

  install -Dm644 mgba-$pkgver/res/mgba-256.png "$pkgdir"/usr/share/pixmaps/io.mgba.mGBA.png

  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s /usr/share/licenses/libmgba/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
